package cn.edu.hunau.thread;

import java.time.LocalTime;
import java.util.concurrent.TimeUnit;

/**
 * @author hb
 * @date 2025-08-18 10:50:40
 */
public class TestJoin {
    public static void main(String[] args) {
        Thread t1=new Thread("t-01"){
            @Override
            public void run() {
                for (int i=1;i<10;i++){
                    try {
                        System.out.println("\t"+getName()+"正在运行 i="+i+" time="+ LocalTime.now());
                        TimeUnit.SECONDS.sleep(1);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }

                }
            }
        };

        Thread t2=new Thread("t-02"){
            @Override
            public void run() {
                for (int i=1;i<10;i++){
                    System.out.println(getName()+"正在运行 i="+i+" time="+ LocalTime.now());
                    if(i==5){
                        try {
                            t1.join();
                        } catch (InterruptedException e) {
                            throw new RuntimeException(e);
                        }
                    }
                }
            }
        };
        t1.start();
        t2.start();
    }
}
